<?php
namespace jy_pinggou;
defined('BY_JYA') or exit('error');
/*
	任务
*/
class task extends \plugin{
	/*
		团UP
	*/
	public function teamup(){
		$pluginset=$this->fenxiaoset;
		$params=array('plugin_name'=>'jy_pinggou','status'=>0);
		$team = pdo_getall('jy_weishop_groups_team',$params,array('id','uniacid','goodsid','createtime'));
		if($team){
			foreach($team as $a){
				$_SESSION['uniacid']=$a['uniacid'];
				$goods=pdo_get('jy_weishop_goods',array('id'=>$a['goodsid']));
				$goods=$this->model('model')->up_price($goods,$pluginset,true);
				$goods['grouptime']=$goods['grouptime']?:10;
				$endtime=$goods['grouptime']*60+$a['createtime'];
				if(time()>$endtime){
					$this->model('model')->order_cancel($a['id']);
				}				
			}
		}
	}
	/*
		自动开团
	*/
	public function openteam(){
		$params=array('status'=>1);
		$goods = pdo_getall('jy_pinggou_goods',$params);
		if($goods){
			foreach($goods as $item){
				$_SESSION['uniacid']=$item['uniacid'];
				$this->model('order')->openteam($item);	
			}
		}
		return false;
	}
	/*
		测试升级
	*/
	public function test(){		
		$pinggoods = pdo_get('jy_pinggou_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>1));
		$params=array(
			'pingid'=>$pinggoods['id'],
			'msg'=>'参与拼团成功！',
			'status'=>1,
			'orderid'=>1660,
			'dayid'=>date('Y-m-d',TIMESTAMP),
			'mid'=>1,
		);
		$this->model('renwu')->canyu($params,$pinggoods);
	}
	/*
		测试分销
	*/
	public function testfenxiao(){		
		$order = pdo_get('jy_weishop_order',array('id'=>2099));
		$pin_goods=pdo_get('jy_pinggou_goods',array('id'=>1,'uniacid'=>$_SESSION['uniacid']));
		$this->model('renwu')->canfen($order,$pin_goods);
	}
	/*
		测试成团
	*/
	public function testsuccess(){		
		$order = pdo_get('jy_weishop_order',array('teamid'=>222));
		$goodsid=pdo_getcolumn('jy_weishop_order_goods',array('uniacid'=>$_SESSION['uniacid'],'orderid'=>$order['id']),'goodsid');
		//拼单部分
		$num=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>10,'teamid'=>$order['teamid']));
		$goods=pdo_get('jy_weishop_goods',array('id'=>$goodsid,'uniacid'=>$_SESSION['uniacid']));
		$goods=$this->model('model')->up_price($goods,$return['pluginset']);
		file_put_contents(ROOT_D.'/2.TXT',$num.'~~'.$goods['teamnum']."\n",FILE_APPEND);
		if($goods['teamnum']<=$num){
			$this->model('model')->order_success($order['teamid']);
		}
	}
}